home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / e / gencodee_v21.lha / GenCodeE / E / DemoGenCodeE30b / DemoGenCodeE.em < prev    next >
Text File  |  1994-11-15  |  6KB  |  187 lines

  1. OPT OSVERSION = 37
  2.  
  3.  
  4. /*/////////////////////////////////////////////////////////////////////////////
  5. ///////////////////////////////////////////////////////////// Macro files /////
  6. ///////////////////////////////////////////////////////////////////////////////
  7. MACROS 'MUI.pma'
  8. */
  9.  
  10.  
  11. ->/////////////////////////////////////////////////////////////////////////////
  12. ->////////////////////////////////////////////////////// External modules /////
  13. ->/////////////////////////////////////////////////////////////////////////////
  14. MODULE 'locale'
  15. MODULE 'muimaster' , 'libraries/mui'
  16. MODULE 'utility/tagitem' , 'utility/hooks'
  17. MODULE 'tools/boopsi' , 'tools/installhook'
  18. MODULE 'icon'
  19.  
  20. MODULE '*GUI'
  21.  
  22.  
  23. ->/////////////////////////////////////////////////////////////////////////////
  24. ->/////////////////////////////////////////// Global variable definitions /////
  25. ->/////////////////////////////////////////////////////////////////////////////
  26. DEF dgce    :    PTR TO app_obj            -> look at GUI.em for "app_obj" object
  27. DEF string_var    :    PTR TO CHAR            -> used by a notification (see GUI.em, lines 49 and 155)
  28.  
  29.  
  30. ->/////////////////////////////////////////////////////////////////////////////
  31. ->//////////////////////////////////////////////////////// Main Procedure /////
  32. ->/////////////////////////////////////////////////////////////////////////////
  33. PROC main() HANDLE
  34.  
  35.     DEF running = TRUE , result_domethod , signal
  36.     DEF arexx : app_arexx , display : app_display
  37.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  38.     DEF icon = NIL
  39.  
  40.         -> needed libraries and icon init
  41.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Throw( "LIB" , "muim" )
  42.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Throw( "LIB" , "icon" )
  43.  
  44.         -> exported variables init
  45.     string_var := 'String variable put !'
  46.  
  47.         -> MUI GUI init
  48.             -> in GUI.em line 22, you can see the declaration of "app_display" object
  49.             -> each field of this object correspond to a hook function declared in MUIBuilder
  50.             -> in the present case, there is only the "button_pressed" hook function (see GUI.em line 167)
  51.     installhook( display.button_pressed , {button_pressed} )
  52.  
  53.         -> ARexx init
  54.             -> for ARexx init you must fill an "app_arexx" object defined in GUI.em line 17
  55.             -> this object gets 2 fields : one for the commands and one for the arexx error hook function
  56.     installhook( change_text_hook , {change_text} )
  57.     arexx.commands := NEW arexx_commands[ 2 ]
  58.     arexx.commands[].mc_name := 'change_text'
  59.     arexx.commands[].mc_template := ''
  60.     arexx.commands[].mc_parameters := 0
  61.     arexx.commands[].mc_hook := change_text_hook
  62.     installhook( arexx.error , {arexx_error} )
  63.  
  64.         -> MUI application creation
  65.             -> for this you call the create method (see GUI.em line 57) on the "app_obj" object
  66.             -> to this method, you must give the "app_display" object
  67.             -> and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete)
  68.     NEW dgce
  69.     IF dgce.create( display , icon , arexx ) = NIL THEN Throw( "MUI" , Mui_Error() )
  70.     dgce.init_notifications( display )
  71.  
  72.         -> Main loop
  73.     WHILE running
  74.  
  75.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  76.         SELECT result_domethod
  77.  
  78.             CASE ID_BUTTON_PRESSED    -> see GUI.em line 42 for the definition of this ID
  79.  
  80.                 set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ID returned !' )
  81.  
  82.             CASE MUIV_Application_ReturnID_Quit
  83.  
  84.                 running := FALSE
  85.  
  86.         ENDSELECT
  87.  
  88.         IF ( signal AND running ) THEN Wait( signal )
  89.  
  90.     ENDWHILE
  91.  
  92. EXCEPT DO
  93.  
  94.     SELECT exception
  95.  
  96.         CASE "LIB"
  97.  
  98.             SELECT exceptioninfo
  99.  
  100.                 CASE "muim"
  101.  
  102.                     error_simple( 'Can''t open muimaster.library !' )
  103.  
  104.                 CASE "icon"
  105.  
  106.                     error_simple( 'Can''t open icon.library !' )
  107.  
  108.             ENDSELECT
  109.  
  110.         CASE "MEM"
  111.  
  112.             error( 'Not enough memory !' )
  113.  
  114.         CASE "MUI"
  115.  
  116.             SELECT exceptioninfo
  117.  
  118.                 CASE MUIE_OutOfMemory
  119.  
  120.                     error_simple( 'Not enough memory !' )
  121.  
  122.                 CASE MUIE_OutOfGfxMemory
  123.  
  124.                     error_simple( 'Not enough chip memory !' )
  125.  
  126.                 CASE MUIE_MissingLibrary
  127.  
  128.                     error_simple( 'Can''t open a needed library !' )
  129.  
  130.                 CASE MUIE_NoARexx
  131.  
  132.                     error_simple( 'Can''t create arexx port !' )
  133.  
  134.                 DEFAULT
  135.  
  136.                     error_simple( 'Internal problem !' )
  137.  
  138.             ENDSELECT
  139.  
  140.     ENDSELECT
  141.  
  142.     IF dgce            THEN dgce.dispose()
  143.     IF icon            THEN FreeDiskObject( icon )
  144.     IF iconbase        THEN CloseLibrary( iconbase )
  145.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  146.  
  147. ENDPROC
  148.  
  149.  
  150. ->/////////////////////////////////////////////////////////////////////////////
  151. ->/////////////////// Prints an error message with an intuition requester /////
  152. ->/////////////////////////////////////////////////////////////////////////////
  153. PROC error_simple( message : PTR TO CHAR ) IS EasyRequestArgs(    NIL , [ 20 , 0 ,
  154.                                     'DemoGenCodeE error !' ,
  155.                                     message ,
  156.                                     '_OK' ] , NIL , NIL )
  157.  
  158.  
  159. ->/////////////////////////////////////////////////////////////////////////////
  160. ->///////////////////////// Prints an error message with an MUI requester /////
  161. ->/////////////////////////////////////////////////////////////////////////////
  162. PROC error( message : PTR TO CHAR ) IS Mui_RequestA(    dgce.app ,
  163.                             dgce.wi_the_window ,
  164.                             NIL ,
  165.                             'DemoGenCodeE error !' ,
  166.                             '*_OK' ,
  167.                             message ,
  168.                             NIL )
  169.  
  170.  
  171. ->/////////////////////////////////////////////////////////////////////////////
  172. ->///////// Hook function called each time bt_call_hook button is pressed /////
  173. ->/////////////////////////////////////////////////////////////////////////////
  174. PROC button_pressed( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , 'Modified by called hook function !' )
  175.  
  176.  
  177. ->/////////////////////////////////////////////////////////////////////////////
  178. ->///////////////////// Hook function called by ARexx command change_text /////
  179. ->/////////////////////////////////////////////////////////////////////////////
  180. PROC change_text( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ARexx command change_text !' )
  181.  
  182.  
  183. ->/////////////////////////////////////////////////////////////////////////////
  184. ->//////////////////////// Hook function called by ARexx in case of error /////
  185. ->/////////////////////////////////////////////////////////////////////////////
  186. PROC arexx_error( hook , obj , msg ) IS error_simple( 'Unknown ARexx command recieved !' )
  187.